package com.yangchuang.openpicture.config;

import com.volcengine.ark.runtime.service.ArkService;
import com.yangchuang.openpicture.property.DoubaoAiProperties;
import okhttp3.ConnectionPool;
import okhttp3.Dispatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.TimeUnit;

@Configuration
public class ArkConfig {

    @Autowired
    private DoubaoAiProperties doubaoAiProperties;

    @Bean
    public ArkService arkService() {
        ConnectionPool connectionPool = new ConnectionPool(5, 1, TimeUnit.SECONDS);
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.setMaxRequestsPerHost(5);

        return ArkService.builder()
                .dispatcher(dispatcher)
                .connectionPool(connectionPool)
                .apiKey(doubaoAiProperties.getApiKey())
                .build();
    }
}
